# -*- coding: utf-8 -*-

import mysql.connector as conn


def unbinding_cookie():
    try:
        mydb = conn.connect(
            host='pro.xdns.cn',
            port="63306",
            user="root",
            passwd="780ecd3443c03ba8B5764EF4C64FF24",
            database='crm')
    except conn.errors.ProgrammingError as e:
        print(f'{e}')
        return


    username = input("请输入用户名：")

    cursor = mydb.cursor()

    query_sql = f"select tu.bindingCookie from tb_user as tu where tu.userName = \"{username}\""

    try:
        cursor.execute(query_sql);
        user_cookie = cursor.fetchall();\
        dig_user_cookie = user_cookie[0]
    except BaseException as e:
        print(f'{e}')
    else:
        unbinding_sql = f"update tb_user as tu set tu.bindingCookie = replace(bindingCookie,\"{dig_user_cookie[0]}\",\"\""
        cursor.execute(unbinding_sql)
        mydb.commit()
        mydb.close()


unbinding_cookie()





